Creating a Canvas
A canvas specifies boundaries out of which RigidBodies won't be able to go unless RigidBody.KeepInCanvas is set to false. By default this canvas is set to workspace.CurrentCamera.ViewportSize
. In order to specify a new canvas, we use the Engine:CreateCanvas()
method.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Nature2D = require(ReplicatedStorage.Nature2D)
local engine = Nature2D.init(screenGuiInstance)
engine:CreateCanvas(Vector2.new(100, 100), Vector2.new(500, 300)) -- topLeft: (100, 100), size: (500, 300)
The above should specify a canvas as such:
In order to render custom constraints and points, it is important to set the "frame" of the canvas. To do that:
engine:CreateCanvas(Vector2.new(100, 100), Vector2.new(500, 300), GuiFrameInstance)
-- OR
engine.canvas.frame = GuiFrameInstance